# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer:
pkgname=phabricator
pkgver=0_git20180717
pkgrel=0
pkgdesc="Open software engineering platform and fun adventure game"
url="http://phacility.com/phabricator/"
arch="noarch"
license="Apache-2.0"
pkggroups=www-data
depends="
	php7
	php7-apcu
	php7-ctype
	php7-curl
	php7-fileinfo
	php7-fpm
	php7-gd
	php7-iconv
	php7-json
	php7-mbstring
	php7-mysqli
	php7-opcache
	php7-pcntl
	php7-posix

	libphutil
	arcanist
	"
subpackages="$pkgname-openrc"
options="!check" # no checks
source="https://dev.alpinelinux.org/archive/phabricator/phabricator-$pkgver.tar.gz
	phd.initd
	"
builddir="$srcdir/phabricator-stable"

build() {
	:
}

package() {
	cd "$builddir"
	mkdir -p "$pkgdir"/usr/share/php/$pkgname \
		"$pkgdir"/usr/bin
	for i in bin conf externals resources scripts src support webroot; do
		cp -r "$builddir"/$i "$pkgdir"/usr/share/php/$pkgname/
	done
	
	install -dm775 -g www-data "$pkgdir"/var/lib/$pkgname/files \
		"$pkgdir"/var/lib/$pkgname/repos
	
	for conf in $(find "$pkgdir"/usr/share/php/$pkgname/conf/* -type d); do
		mkdir -p "$pkgdir"/etc/$pkgname
		mv "$conf" "$pkgdir"/etc/$pkgname/
		chmod 775 "$pkgdir"/etc/$pkgname
		chmod 664 "$pkgdir"/etc/$pkgname/*/*
		chgrp www-data -R "$pkgdir"/etc/$pkgname
		ln -sf /etc/$pkgname/"${conf##*/}" "$conf"
	done

	install -Dm755 "$srcdir"/phd.initd "$pkgdir"/etc/init.d/phd
}

snapshot() {
	local pkgver=0_git$(date +%Y%m%d)
	msg "Grabbing the latest stable snapshot"
	mkdir -p "$srcdir"
	wget -O "$srcdir"/$pkgname-$pkgver.tar.gz \
		https://github.com/phacility/phabricator/archive/stable.tar.gz
	ssh distfiles.alpinelinux.org \
		"mkdir -p archive/$pkgname/"
	scp "$srcdir"/$pkgname-$pkgver.tar.gz \
		dev.alpinelinux.org:/archive/$pkgname/
	sed -i -e "s/^pkgver=.*/pkgver=$pkgver/" \
		"$startdir"/APKBUILD
	sed -i -e "s/^pkgrel=.*/pkgrel=0/" \
		"$startdir"/APKBUILD
	abuild checksum
}

sha512sums="b749c6b0aaa759626ee753d128b802c8e8f6262a7e8bdc2261f0ab6b5873c941dfd3917eb7e53bed0fa263d2356890f74e08c1a7eebb5836ee1aa6af52c7f976  phabricator-0_git20180717.tar.gz
aabcb6ccc660041cdf13d0c5070b205c8cc2aa09d7801b8c9d06da104cc3aca6c03597291c8f9086f8918601280377df66adf9f7b017b517e78c84cf0f92ea7b  phd.initd"
